package com.jrx.anytxn.atom.service.impl;

import com.jrx.anytxn.atom.bean.CustBatchSaveBean;
import com.jrx.anytxn.atom.service.BaseBatchAccoutHandle;
import com.jrx.anytxn.customer.entity.CmCustomerFirstLevel;
import com.jrx.anytxn.transaction.bean.BlockCodeSaveBean;
import com.jrx.anytxn.transaction.entity.AmLoanAccountInfo;
import com.jrx.anytxn.transaction.service.ICustBlockCodeService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: anytxn-cf-parent
 * @author: lbz
 **/
@Order(210)
@Service
public class BlockCodeHandle extends BaseBatchAccoutHandle<BlockCodeSaveBean> {

    Logger logger = LoggerFactory.getLogger(BlockCodeHandle.class);

    @Autowired
    private ICustBlockCodeService custBlockCodeService;

    @Override
    public List<BlockCodeSaveBean> handBatchAccout() throws Exception {
        CustBatchSaveBean custBatchSaveBean = CustBatchHelper.getCustBatchLocal();

        List<AmLoanAccountInfo> accountInfoList = custBatchSaveBean.getDealLoanAccountList();

        List<BlockCodeSaveBean> blockCodeSaveBeanList = new ArrayList<>();

        CmCustomerFirstLevel firstLevel = custBatchSaveBean.getUpdateCust();

        BlockCodeSaveBean blockCodeSaveBean = custBlockCodeService.buildBlockCode(firstLevel,accountInfoList);

        blockCodeSaveBeanList.add(blockCodeSaveBean);
        logger.info("BlockCodeHandle用户:{},需要处理的订单：{}",
                custBatchSaveBean.getDealCust().getCustomerId(),
                custBatchSaveBean.getDealLoanAccountList().stream().map(AmLoanAccountInfo::getLoanId).collect(Collectors.joining(","))
        );
        return blockCodeSaveBeanList;
    }
}
